{js:artTemplate}
<script type='text/javascript' src='{theme:javascript/artTemplate/area_select.js}'></script>
<div class="main f_r">
    <div class='tabs'>
		<div class="uc_title m_10 tabs_menu">
			<label class="current node"><span>地址管理</span></label>
			<label class="node" onclick='form_empty()'><span>添加地址</span></label>
		</div>
	    <div class='tabs_content'>
	        <div id="address_list" class="form_content m_10 node">
	            <div class="uc_title2 m_10"><strong>已保存的有效地址</strong></div>
	            <table class="list_table" width="100%" cellpadding="0" cellspacing="0">
	                <col width="120px" />
	                <col width="120px" />
	                <col width="120px" />
	                <col width="120px" />
	                <col width="120px" />
	                <col />
	                <thead>
	                	<tr>
	                		<th>收货人</th>
	                		<th>所在地区</th>
	                		<th>街道地址</th>
	                		<th>电话/手机</th>
	                		<th>邮编</th>
	                		<th>操作</th>
	                	</tr>
	                </thead>
	                <tbody>
	                {foreach:items=$this->address}
	                    <tr {if:$key%2==1}class='even'{/if}>
	                        <td>{$item['accept_name']}</td>
	                        <td>{$this->areas[$item['province']]}{$this->areas[$item['city']]}{$this->areas[$item['area']]}</td>
	                        <td>{$item['address']}</td>
	                        <td>{$item['mobile']}</td>
	                        <td>{$item['zip']}</td>
	                        <td>
	                        	<a class="blue" href='javascript:void(0)' onclick='form_back({echo:JSON::encode($item)})'>修改</a>|
	                        	<a class="blue" href="javascript:void(0)" onclick="delModel({link:'{url:/ucenter/address_del/id/$item[id]}'});">删除</a>|
	                        	{if:$item['default']==1}
	                        	<a class="red2" href="{url:/ucenter/address_default/id/$item[id]/default/0}">取消默认</a>
	                        	{else:}
	                        	<a class="blue" href="{url:/ucenter/address_default/id/$item[id]/default/1}">设为默认</a>
	                        	{/if}
	                        </td>
	                    </tr>
	                {/foreach}
	                </tbody>
	            </table>
	        </div>
	    </div>
    </div>

	<!--表单修改-->
	<div class="orange_box" id='address_form'>
		<form action='{url:/ucenter/address_edit}' method='post' name='form'>
			<input name='id' type='hidden' value='' />
			<table class="form_table" width="100%" cellpadding="0" cellspacing="0">
				<col width="120px" />
				<col />
				<caption>收货地址</caption>
				<tr>
					<th><span class="red">*</span> 收货人姓名：</th>
					<td><input name='accept_name' class="normal" pattern='required' alt='收货人不能为空' type="text" /><label>收货人真实姓名，方便快递公司联系。</label></td>
				</tr>
				<tr>
					<th><span class="red">*</span> 所在地区：</th>
					<td>
						<select name="province" child="city,area" onchange="areaChangeCallback(this);"></select>
						<select name="city" child="area" parent="province" onchange="areaChangeCallback(this);"></select>
						<select name="area" parent="city" pattern="required"></select>
					</td>
				</tr>
				<tr>
					<th><span class="red">*</span> 街道地区：</th><td><input name='address' class="normal" pattern='required' alt='街道地区不能为空' type="text" /><label>真实详细收货地址，方便快递公司联系。</label></td>
				</tr>
				<tr>
					<th>邮政编码：</th>
					<td><input name='zip' class="normal" pattern='^\d{6}$' empty alt='邮政编码格式不正确' type="text" /><label>邮政编码,如250000。</label></td>
				</tr>
				<tr>
					<th>电话号码：</th>
					<td><input name='telphone' class="normal" pattern='phone' empty alt='电话号码格式不正确' type="text" /><label>电话号码,如010-12345688。</label></td>
				</tr>
				<tr>
					<th>手机号码：</th>
					<td><input name='mobile' class="normal" pattern='mobi' empty alt='手机号码格式不正确' type="text" /><label>手机号码，如：13588888888</label></td>
				</tr>
				<tr>
					<th>设为默认：</th>
					<td><label><input name='default' type='checkbox' value='1'></label></td>
				</tr>
				<tr>
					<th></th>
					<td>
						<label class="btn"><input type="submit" value="保存" /></label>
						<label class="btn"><input type="reset" value="取消" /></label>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>

<script type='text/javascript'>
//DOM加载完毕
$(function(){
	//初始化地域联动
	template.compile("areaTemplate",areaTemplate);

	createAreaSelect('province',0,'');
});

/**
 * 生成地域js联动下拉框
 * @param name
 * @param parent_id
 * @param select_id
 */
function createAreaSelect(name,parent_id,select_id)
{
	//生成地区
	$.getJSON("{url:/block/area_child}",{"aid":parent_id,"random":Math.random()},function(json)
	{
		$('[name="'+name+'"]').html(template.render('areaTemplate',{"select_id":select_id,"data":json}));
	});
}

//修改地址
function form_back(obj)
{
    //自动填充表单
	var form = new Form('form');
	form.init(obj);

	createAreaSelect('province',0,obj.province);
	createAreaSelect('city',obj.province,obj.city);
	createAreaSelect('area',obj.city,obj.area);
}

//清空表单
function form_empty()
{
	var formInstance = new Form('form');
	$('form[name="form"] input[name]').each(function(){
		formInstance.setValue(this.name,'');
	});

	createAreaSelect('province',0,'');
	$('select[name="city"]').empty();
	$('select[name="area"]').empty();
}
</script>
